/* eslint-disable no-undef */
import React, { useEffect } from 'react'
export default function Index() {
  useEffect(() => {
    const map = new BMapGL.Map("container");
    const point = new BMapGL.Point(116.404, 39.915);
    map.centerAndZoom(point, 15);
    // 设置地图类型
    map.setMapType(BMAP_EARTH_MAP);
    map.enableScrollWheelZoom(true); // 开启鼠标滚轮缩放
    //通过点击事件获取经纬度坐标
    map.addEventListener("click", (e) => {
      console.log("点击的经纬度：" + e.latlng.lng + ", " + e.latlng.lat);
    });

    var geolocation = new BMapGL.Geolocation();
    geolocation.getCurrentPosition(function (r) {
      if (this.getStatus() === BMAP_STATUS_SUCCESS) {
        var mk = new BMapGL.Marker(r.point);
        map.addOverlay(mk);
        map.panTo(r.point);
        console.log("您的位置：" + r.point.lng + "," + r.point.lat);
      } else {
        console.log("failed" + this.getStatus());
      }
    });
  },[])
  return <div id="container" style={{width:'100%',height:'100%'}}></div>;
}
